using System;
using System.Collections.Generic;
using System.Reflection;
using WindowsPhoneMVC.Navigation.Interfaces;

namespace WindowsPhoneMVC.Tests.Navigation.Fakes
{
    public class FakeControllerLocator : IControllerLocator
    {
        private readonly Dictionary<string, Type> controllerRegistrar = new Dictionary<string, Type>();

        public void Register<T>() where T : Controller
        {
            var controllerType = typeof (T);
            controllerRegistrar.Add(controllerType.Name, controllerType);
            controllerRegistrar.Add(controllerType.Name.Replace("Controller", string.Empty), controllerType);
        }

        public void AddAssemblyToScan(Assembly assembly)
        {
            
        }

        public Type Locate(string controllerName)
        {
            if (controllerRegistrar.ContainsKey(controllerName)) 
                return controllerRegistrar[controllerName];

            throw new InvalidOperationException(string.Format("The test needs to register controller {0} with locator", controllerName));
        }
    }
}